// pages/me/me.js
import {
  PersonModel
} from '../../models/hdd/personal.js'
let personModel = new PersonModel()
import {
  LoginModel
} from '../../models/hdd/login.js'
let loginModel = new LoginModel()
import {
  AuthModel
} from '../../models/hdd/authData.js'
let authModel = new AuthModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    personalData: '',
    FCompamyPhoto: '',
  },

  pushToOrderList() {
    wx.navigateTo({
      url: '/pages/orderList/orderList',
    })
  },

  logout() {
    wx.showModal({
      showCancel: true,
      title: '提示',
      content: '确定要注销吗?',
      success(res) {
        if (res.confirm) {
          const logout = loginModel.logout()
          logout.then(res => {
            if (res.data.success) {
              wx.reLaunch({
                url: '/pages/login/login',
              })
            }
          })
        }
      }
    })
  },

  pushToAuth() {
    wx.navigateTo({
      url: `/pages/auth/auth?FItEmpId=${this.data.personalData.FId}`,
    })
  },

  pushToPersonInfo() {
    wx.navigateTo({
      url: `/pages/personInfo/personInfo?personalData=${JSON.stringify(this.data.personalData)}`
    })
  },

  pushToEditPersonInfo() {
    wx.navigateTo({
      url: `/pages/companyDetail/companyDetail?fromPage=me&mobile=${this.data.personalData.FMobile}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '公司信息'
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#FF7136',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    wx.showLoading({
      mask: true
    })
    const personal = personModel.getPersonalData()
    personal.then(res => {
      wx.hideLoading()
      console.log(res)
      this.setData({
        personalData: res.data.data.data.company,
        FCompamyPhoto: res.data.data.data.company.platformAuthen.FCompamyPhoto ? res.data.data.data.company.platformAuthen.FCompamyPhoto : ''
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})